import axios from 'axios'

export const browserDebug = false
const prefix = browserDebug ? '/api' : ''

/**
 * 获取商品 sku 详情
 * @param {*} id 商品 id
 */
export const getSkuApi = function (id) {
  return axios.get(`${prefix}/shop/sku/${id}`)
}

/**
 * 添加商品进购物车
 * @param {*} data 商品信息
 */
export const cartAddApi = function (data) {
  return axios.post(`${prefix}/shop/cart/add`, data)
}

/**
 * 获取购物车数据
 */
export const cartApi = function () {
  return axios.get(`${prefix}/shop/cart`)
}

/**
 * 账号密码登录接口
 * @param {*} data
 */
export const loginApi = function (data) {
  return axios.post(`/token/passport/login`, data)
}

/**
 * 获取签到列表接口
 */
export const signinListApi = function () {
  return axios.get(`${prefix}/user/signin`)
}

/**
 * 今日签到接口
 */
export const signinCreateApi = function () {
  return axios.post(`${prefix}/user/signin/create`)
}

/**
 * export const getProductInfo = (id) => axios({
  method: 'get',
  url: '/shop/spu/' + id,
  params: {},
  headers: {}
})
*/

/**
 * 获取商品详情
 * @param id 商品ID
 */
export const getProductInfoApi = (id) => {
  return axios.get('/shop/spu/' + id)
}

/**
 * 获取当前购物车商品数量
 * @param none
 */
export const getCartNumberApi = () => axios({
  method: 'get',
  url: '/shop/cart/number',
  headers: {
    FastMode: true
  }
})

/**
 * 加入购物车
 * @param data 参数
 * ```
 * {
 *   product_id: 商品ID,
 *   goods_id: SKU ID,
 *   nums: 数量
 * }
 * ```
 */
export const postAddCartApi = (data) => axios({
  method: 'post',
  url: '/shop/cart/add',
  data: data,
  headers: {
    FastMode: true
  }
})

/**
 * 商城收藏商品、店铺
 * @param data 参数信息
 * ```
 * {
 *   product_id: 商品ID,
 *   store_id: 店铺ID
 * }
 * ```
 */
export const postShopCollectApi = (data) => axios({
  method: 'post',
  url: '/shop/extend/collect',
  data: data,
  headers: {
    FastMode: true
  }
})
